using System;
using System.Collections;
using System.Collections.Generic;
using Storage.Core;
using System.Linq;

namespace Storage.Server
{
    internal class Scope : IEnumerable<KeyValuePair<Guid, PlainEntity>>
    {
        readonly Dictionary<Guid, PlainEntity> entities;

        public Scope()
        {
            entities = new Dictionary<Guid, PlainEntity>();
        }

		public IList<PlainEntity> ToList()
        {
            return entities.Values.ToList();
        }

		public void AddOrUpdate(PlainEntity entity)
		{
			entities[entity.Id] = entity;
		}

        public IEnumerator<KeyValuePair<Guid, PlainEntity>> GetEnumerator()
        {
            return entities.GetEnumerator();
        }

		public bool Remove(Guid id)
		{
			return entities.Remove(id);
		}

    	IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

		public int Count { get { return entities.Count; } }
    }
}